<?php


namespace app\miniProgram\controller;


use think\Exception;
use think\facade\Db;

class ProcessReporting extends Auth
{
    protected $table='process_reporting';
    public function onSure()
    {
        $validate=new \app\miniProgram\validate\Action();
        if(!$validate->scene('processReport')->check($this->param)){
            return $this->jump(0,$validate->getError());
        }

        Db::connect('company')->startTrans();
        try {
            $data=[
                'correlation_order'=>$this->param['correlation_order'],
                'material_dossier_id'=>$this->param['material_dossier_id'],
                'craft_detail_id'=>$this->param['craft_detail_id'],
                'pricing_mode'=>$this->param['pricing_mode'],
                'u_g_id'=>$this->param['u_g_id'],
                'orderDate'=>$this->param['orderDate']??date('Y-m-d'),
                'qualifiedNum'=>$this->param['qualifiedNum'],
                'passNum'=>$this->param['passNum'],
                'wasteNum'=>$this->param['wasteNum'],
                'is_end'=>$this->param['is_end']??1,
                'status'=>2,
                'create_time'=>time(),
                'update_time'=>time()
            ];
            $id = Db::connect('company')->name($this->table)->strict(false)->field(true)->insertGetId($data);
           $sres=\app\home\severs\ProcessReporting::onSure(['id'=>$id],$this->userInfo['id']);
           if ($sres['code']==1){
               throw new Exception($sres['msg']);
           }
            Db::connect('company')->commit();
        }catch (\Exception $e){
            Db::connect('company')->rollback();
            return $this->jump(0,$e->getMessage());
        }
        return $this->jump(1,'操作成功');
}
}